package com.wz.project.stock.main.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.stock.main.domain.BasStockMain;
import com.wz.project.stock.main.service.IBasStockMainService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 主库存Controller
 * 
 * @author wz
 * @date 2022-12-05
 */
@Controller
@RequestMapping("/stockMain/main")
public class BasStockMainController extends BaseController
{
    private String prefix = "stockMain/main";

    @Autowired
    private IBasStockMainService basStockMainService;

    @RequiresPermissions("stockMain:main:view")
    @GetMapping()
    public String main()
    {
        return prefix + "/main";
    }

    /**
     * 查询主库存列表
     */
//    @RequiresPermissions("stockMain:main:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasStockMain basStockMain)
    {
        startPage();
        List<BasStockMain> list = basStockMainService.selectBasStockMainList(basStockMain);
        return getDataTable(list);
    }

    /**
     * 导出主库存列表
     */
    @RequiresPermissions("stockMain:main:export")
    @Log(title = "主库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasStockMain basStockMain)
    {
        List<BasStockMain> list = basStockMainService.selectBasStockMainList(basStockMain);
        ExcelUtil<BasStockMain> util = new ExcelUtil<BasStockMain>(BasStockMain.class);
        return util.exportExcel(list, "main");
    }

    /**
     * 新增主库存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存主库存
     */
    @RequiresPermissions("stockMain:main:add")
    @Log(title = "主库存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasStockMain basStockMain)
    {
        return toAjax(basStockMainService.insertBasStockMain(basStockMain));
    }

    /**
     * 修改主库存
     */
    @GetMapping("/edit/{stockId}")
    public String edit(@PathVariable("stockId") String stockId, ModelMap mmap)
    {
        BasStockMain basStockMain = basStockMainService.selectBasStockMainById(stockId);
        mmap.put("basStockMain", basStockMain);
        return prefix + "/edit";
    }

    /**
     * 修改保存主库存
     */
    @RequiresPermissions("stockMain:main:edit")
    @Log(title = "主库存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasStockMain basStockMain)
    {
        return toAjax(basStockMainService.updateBasStockMain(basStockMain));
    }

    /**
     * 删除主库存
     */
    @RequiresPermissions("stockMain:main:remove")
    @Log(title = "主库存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basStockMainService.deleteBasStockMainByIds(ids));
    }
}
